﻿using System;

namespace LiJ.Common.Extention.Volidate
{
    /// <summary>
    /// 必填验证属性
    /// </summary>
    public class LRequiredAttribute : BaseValidateAttribute
    {
        /// <summary>
        /// 必填验证构造函数
        /// </summary>
        /// <param name="_errorMessage">错误提示消息</param>
        public LRequiredAttribute(string _errorMessage = null)
        {
            base.errorMessage = _errorMessage;
        }

        /// <summary>
        /// 必填验证校验方法
        /// </summary>
        /// <param name="propertyName">属性名称</param>
        /// <param name="propertyValue">属性值</param>
        /// <returns><c>true</c><value>校验正确</value><c>false</c><value>校验失败</value></returns>
        internal override bool Validate(string propertyName, object propertyValue)
        {
            var flag = propertyValue != null && propertyValue.ToString() != String.Empty;
            if (!flag)
            {
                base.errorMessage = (base.errorMessage ?? $"请输入{propertyName}信息");
            }

            return flag;
        }
    }
}